import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
import { visualizer } from "rollup-plugin-visualizer";
import externalGlobals from "rollup-plugin-external-globals";

const globals = externalGlobals({
  dayjs: "dayjs",
  echarts: "echarts",
});

export default defineConfig({
  plugins: [
    react(),
    // 打包体积分析
    visualizer({
      open: true,
      filename: "visualizer.html", //分析图生成的文件名
    }),
  ],
  resolve: {
    alias: {
      //  @ ==> /src
      "@": path.resolve(__dirname, "src"),
    },
  },
  build: {
    minify: "terser",
    // 清除所有console和debugger
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
    rollupOptions: {
      //打包时不引入外部模块，使用cdn引入
      external: ["dayjs", "echarts"],
      plugins: [globals],
    },
  },
});
